<template>
  <base-breadcrumb :title="titleName">
    <searchData
      :search-data="searchArr"
      @search="search"
    />

    <a-card :bordered="false">
      <!-- <title-name title="设计成果资料登记列表" /> -->

      <!-- <div style="margin-bottom: 20px">
        <a-button
          type="primary"
          @click="handleAdd()"
        >
          新增设计成果资料
        </a-button>
      </div>

      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px"> 设计成果资料总数：<span class="totalNum">{{ totalSize }} 个</span></span>
      </div> -->

      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :export-config="{ use: true, select: '设计成果资料登记列表', all: '设计成果资料登记列表' }"
      >
        <template
          slot="prefix"
          slot-scope="ref"
        >
          <a-button
            type="primary"
            @click="handleAdd()"
            v-btn-permission="'ds_014_add_01'"
          >
            新增设计成果资料
          </a-button>
        </template>
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="status"
          slot-scope="text"
        >
          <a-badge
            :status="text | statusTypeFilter"
            :text="text | statusFilter"
          />
        </span>
        <span
          slot="description"
          slot-scope="text"
        >
          <ellipsis
            :length="8"
            tooltip
          >{{ text }}</ellipsis>
        </span>
        <span
          slot="actions"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="handleDels(record)" v-btn-permission="'ds_014_loo_02'">查看</a>
            <a @click="handleEdit(record)" v-btn-permission="'ds_014_edi_03'">编辑</a>
          </MoreButton>
        </span>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { getExteriorList } from '@/api/design/designRegister'
  import { getTypes } from '@/api/commons'
  import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司

  import ARow from 'ant-design-vue/es/grid/Row'
  import OrgTreeSelect from '@/components/OrgTreeSelect'



  const columns = [
    {
      title: '序号',
      width: '65px',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '设计成果资料名称',
      dataIndex: 'name'
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',
    },
    {
      title: '分公司',
      dataIndex: 'branchCompanyName',
    },
    {
      title: '资料类型',
      dataIndex: 'typeDataName',
      minWidth: '90px'
    },
    {
      title: '版本',
      width: '65px',
      dataIndex: 'exteriorVersion',
    },
    {
      title: '出图日期',
      dataIndex: 'pubDate',
    },
    {
      title: '签收日期',
      dataIndex: 'receiptDate',
    },
    {
      title: '创建人',
      // width: '120px',
      minWidth: '80px',
      dataIndex: 'creatorName',
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
    },
    {
      title: '操作',
      dataIndex: 'actions',
      width: '150px',
      fixed:'right',
      scopedSlots: { customRender: 'actions' }
    }
  ]

  export default {
    name:'a'+Date.now(),
    components: {
      STable,
      Ellipsis,
    },
    data() {
      this.columns = columns
      return {
        searchArr : [
          // 搜索框
          {
            name: '设计成果资料名称',
            value: 'name',
            type: 'input'
          },
          {
            name: '项目名称',
            value: 'projectName',
            type: 'input'
          },
          {
            name: '所属单位',
            valueKey: 'searchQuery',
            type: OrgTreeSelect
          },
          {
            name: '创建时间',
            value: 'createTime',
            type: 'dateRange'
          },
          {
            name: '创建人',
            value: 'employeeName',
            type: 'input'
          },
          {
            name: '资料类型',
            value: 'dataType',
            type: 'select',
            data:[]
          },
          {
            name: '版本',
            value: 'exteriorVersion',
            type: 'select',
            data:[
              {value:'A', label:'A' },
              {value:'B', label:'B' },
              {value:'C', label:'C' },
              {value:'D', label:'D' },
              {value:'E', label:'E' },
              {value:'F', label:'F' },
              {value:'G', label:'G' },
              {value:'H', label:'H' },
              {value:'I', label:'I' },
              {value:'J', label:'J' }
            ]
          },
          {
            name: '出图日期',
            value: 'plotTime',
            type: 'dateRange'
          },
        ],
        titleName:'',
        totalSize:'',

        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getExteriorList(requestParameters)
            .then(res => {
              this.totalSize = res.totalSize
              return res
            })
        },
        selectedRowKeys: [],
        selectedRows: [],
        totalDels:{},
      }
    },

    created() {
      this.getTypes()
    },
    computed: {
      rowSelection() {
        return {
          selectedRowKeys: this.selectedRowKeys,
          selectedRows: this.selectedRows,   // 当前行所有数据
          onChange: this.onSelectChange
        }
      }
    },
    methods: {
      search(val){
        this.queryParam = val
        console.log(this.queryParam, 1)
        if(val.createTime&&val.createTime.length){
            this.queryParam.creatStartTime = this.formatDate((val.createTime[0]))
            this.queryParam.creatEndTime = this.formatDate((val.createTime[1]))
          } else {
            delete this.queryParam.creatStartTime
            delete this.queryParam.creatEndTime
           }
        if(val.plotTime&&val.plotTime.length){
          this.queryParam.plotStartTime = this.formatDate((val.plotTime[0]))
          this.queryParam.plotEndTime = this.formatDate((val.plotTime[1]))
        } else {
          delete this.queryParam.plotStartTime
          delete this.queryParam.plotEndTime
        }
        console.log(this.queryParam, 2)
        this.$refs.table.getData(null, true)
      },
      getTypes(){
        getTypes({type:26}).then(res=>{
          this.searchArr[5].data = this.getChangeDatatTypes(res.data)
        })
      },
      handleAdd(val){   // 新增设计成果资料
        this.$router.push({path:'/designRegister/add',query:{isEdit:0}})
      },


      handleDels(val){
        this.$router.push({path:'/designRegister/details',query:{id:val.id}})
      },

      handleEdit(val){
        this.$router.push({path:'/designRegister/edit',query:{id:val.id,isEdit:1}})
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },

    }
  }
</script>


